<style>
	.priority_high{
		border-right: 3px solid rgb(255, 0, 0);
		width: 0px;
	}
	.priority_medium{
		border-right: 3px solid rgb(0, 204, 102);
		width: 0px;
	}
	.priority_low{
		border-right: 3px solid rgb(255, 255, 0);
		width: 0px;
	}
	.priority_none{
		border-right: 3px solid rgb(255, 255, 255);
		width: 0px;
	}
	td div { position: relative; }
</style>

<?php 
$previous_month 	= ($month_id - 1);
$next_month		 = ($month_id + 1);
?>
<ul class="pager">
<?php if($previous_month > 0) {?>
  <li class="previous">
    <a href="<?php echo site_url('user/to_do/view/'.$this->session->userdata('user_id').'/'.$previous_month.'/'.$year_id)?>">&larr; Previous Month</a>
  </li>
  <?php } if($next_month <= 12) {?>
  <li class="next">
    <a href="<?php echo site_url('user/to_do/view/'.$this->session->userdata('user_id').'/'.$next_month.'/'.$year_id)?>">Next Month &rarr;</a>
  </li>
  <?php }?>
</ul>
<div class="row-fluid">
	<div class="span9">
	<h4>To Do List For The Month Of <?= date("F", mktime(0, 0, 0, $month_id, 10))?> For <?php echo ucfirst($this->common_model->get_username_id($userid)); ?></h4>
<?php 
$d = '20'.$year_id;
$num = cal_days_in_month(CAL_GREGORIAN, $month_id , $d );
?>
<table class="table table-condensed table-bordered" style="font-size: 11px">	
	<?php 	
		for($i=1;$i<=$num;$i++) {?>		
		<tr>
		<td width="15%"><b><?php echo date("F", mktime(0, 0, 0, $month_id, 10)).' '.$i?></b></td>
		<td>
		<table class="table table-condensed table-bordered" >	
				<?php $fav_todos = $this->todo_model->fav_todo($i,$month_id,$year_id,$userid);
				foreach($fav_todos as $pt){	
				if( ($i == date('d') AND $month_id == date('m') AND $year_id == date('y')) OR ($i == $pt->date_id)){ ?>
				<tr>
				<td ></td>
				<td width="2%">
					<?php if($pt->is_completed == 0) {?>
					 <a href="<?php echo site_url('user/to_do/complete/'.$pt->id.'/'.$i.'/'.$month_id.'/'.$year_id);?>"><i class="icon-ok-circle muted"></i></a>
					 <?php }else {?>
					 <a href="<?php echo site_url('user/to_do/incomplete/'.$pt->id);?>"><i class="icon-ok-sign text-success"></i></a>
					 <?php }?>
				</td>
					<td <?php if(($i == $pt->date_id)){ echo 'class="text-info" title="Todays Todo" ';}else{echo 'class="text-warning" title="Forwarded Todo" ';} ?> >
					<span <?php if($pt->is_completed == 1) {?>
					style="text-decoration: line-through;"					
					<?php }?> >  <?php echo $pt->des?>
						</span>
					</td>
					<td width="3%">			
					<a href="javascript:void(0)" onclick="rem_fav(<?php echo $pt->id?>,<?php echo $i;?>)"><i class="icon-star"></i></a> 					
				</td>
					<td width="7%">
					<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  <b class="caret"></b>
  </a>
					<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">						
						<?php if(!$this->ion_auth->is_admin($this->session->userdata('user_id'))){?> 
					 	<li><a href="<?php echo site_url('user/to_do/worksheet/'.$pt->id);?>" class="add_worksheet"><i class="icon-plus text-error"></i> <span class="text-error"> Add To Worksheet</span> </a></li>
						<?php }?>						
						<li><a href="<?php echo site_url('user/to_do/get_todo/'.$pt->id);?>" class="get_todo"><i class="icon-edit"></i> Edit ToDo </a></li>	
						<li><a href="javascript:void(0)" onclick="delete_todo(<?php echo $pt->id?>)"><i class="icon-trash"></i> Delete </a></li>
					 </ul>
					</div>						
					</td>
				</tr>
				<?php }}?>
				
			<?php $per_todo = $this->todo_model->todo($i,$month_id,$year_id,$userid);				
				foreach($per_todo as $pt){ ?>
				<tr>
				<td <?php if(($pt->priority=="high")){echo 'class="priority_high"' ;}elseif(($pt->priority=="medium")){echo 'class="priority_medium"';}elseif(($pt->priority=="low")){ echo 'class="priority_low"';}else{ echo 'class="priority_none"';} ?>></td>
				<td width="3%">
					<?php if($pt->is_completed == 0) {?>
					 <a href="<?php echo site_url('user/to_do/complete/'.$pt->id.'/'.$i.'/'.$month_id.'/'.$year_id);?>"><i class="icon-ok-circle muted"></i></a>
					 <?php }else {?>
					 <a href="<?php echo site_url('user/to_do/incomplete/'.$pt->id);?>"><i class="icon-ok-sign text-success"></i></a>
					 <?php }?>
				</td>
					<td>
					<span <?php if($pt->is_completed == 1) {?>
					style="text-decoration: line-through;"					
					<?php }?> >  <?php echo $pt->des?>
						</span>
					</td>
					<td width="3%">	
									
				</td>
					<td width="7%">
					<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  <b class="caret"></b>
  </a>
					<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
						
						<?php if(!$this->ion_auth->is_admin($this->session->userdata('user_id'))){?> 
					 	<li><a href="<?php echo site_url('user/to_do/worksheet/'.$pt->id);?>" class="add_worksheet"><i class="icon-plus text-error"></i> <span class="text-error"> Add To Worksheet</span> </a></li>
						<?php }?>
						<?php if($pt->is_completed == 0) {?>
						<li><a href="javascript:void(0)" onclick="add_fav(<?php echo $pt->id?>)"><i class="icon-star"></i> Add to Fav </a></li>
						<?php }?>
						<li><a href="<?php echo site_url('user/to_do/get_todo/'.$pt->id);?>" class="get_todo"><i class="icon-edit"></i> Edit ToDo </a></li>	
						<li><a href="javascript:void(0)" onclick="delete_todo(<?php echo $pt->id?>)"><i class="icon-trash"></i> Delete </a></li>
					 </ul>
					</div>						
					</td>
				</tr>
				<?php }?>	
				
				
		</table>
		</td>		
		</tr>		
	<?php }?>
	</table>
</div>


<div class="span3">
<h3>Add to To-Do</h3>
<form action="<?php echo site_url('user/to_do/save/'.$userid)?>" method="POST">
<table>
	<tr>
		<td>
			Date : <br />
			<input type="text" class="datepicker" name="date" value="<?php echo date('Y-m-d');?>"/>
		</td>
		<tr/>
	<tr>
		<td>			
			Description : <br />
			<textarea name="desc"></textarea>			
		</td>
	</tr>
	
	<tr>
		<td>
		<div class="pull-left">
			<input class="checkbox" type="checkbox" name="is_fav" value="1" checked/> &nbsp;&nbsp;Pin
		</div>
		<div class="pull-right">	
			<select name="priority_is" class="span12"><option value="">No Priority</option><option value="low">Low</option><option value="medium">Medium</option><option value="high">High</option></select>
		</div>	
		</td>
		</tr>
	
	<tr><td><input type="submit" value="Add to To Do List" class="btn"  /></td></tr>
	</tr>
</table>
</form>
<h4>Note</h4>
<div class="text-info"><i class="icon-info"></i> Todays Todo</div> 
<div class="text-warning"><i class="icon-info"></i> Forwarded Todo </div>

<br>
<div class="text-error"><i class="icon-info"></i> High Priority</div> 
<div class="text-warning"><i class="icon-info"></i> Medium Priority</div>
<div class="text-success"><i class="icon-info"></i> Low Priority</div>
	</div>
</div>

<script type="text/javascript">
<!--
	function delete_todo(Id){									
		$.post('<?= site_url("user/to_do/delete");?>',{id:Id}, function(replies) {			
			location.reload();  		
	});
	}
	
	
	
$('.add_worksheet').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});
	
$('.get_todo').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});	
//-->

function add_fav(Id){	
	$.post('<?= site_url("user/to_do/add_fav");?>',{id:Id}, function(replies) {			
			location.reload();  		
	});
}

function rem_fav(Id,date_id){
	$.post('<?= site_url("user/to_do/rem_fav/$month_id/$year_id");?>',{id:Id,dateId:date_id}, function(replies) {			
			location.reload();  		
	});
}

</script>

